package model

import "time"

// SensitiveWord 敏感词模型
type SensitiveWord struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Word      string    `gorm:"size:100;not null;uniqueIndex;comment:敏感词" json:"word"`
	Category  string    `gorm:"size:50;index;comment:分类" json:"category"` // political, violence, porn, ad, etc
	Level     string    `gorm:"type:enum('LOW','MEDIUM','HIGH');default:'MEDIUM';comment:敏感级别" json:"level"`
	Action    string    `gorm:"type:enum('REPLACE','REJECT','WARN');default:'REPLACE';comment:处理动作" json:"action"` // REPLACE(替换), REJECT(拒绝), WARN(警告)
	IsEnabled bool      `gorm:"default:true;comment:是否启用" json:"isEnabled"`
	CreatedBy uint      `gorm:"comment:创建人ID" json:"createdBy"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

// TableName 指定表名
func (SensitiveWord) TableName() string {
	return "sensitive_words"
}

// SensitiveWordCategory 敏感词分类常量
const (
	SensitiveWordCategoryPolitical = "political" // 政治敏感
	SensitiveWordCategoryViolence  = "violence"  // 暴力
	SensitiveWordCategoryPorn      = "porn"      // 色情
	SensitiveWordCategoryAd        = "ad"        // 广告
	SensitiveWordCategoryAbuse     = "abuse"     // 辱骂
	SensitiveWordCategoryOther     = "other"     // 其他
)

// SensitiveWordLevel 敏感词级别
const (
	SensitiveWordLevelLow    = "LOW"    // 低敏感
	SensitiveWordLevelMedium = "MEDIUM" // 中敏感
	SensitiveWordLevelHigh   = "HIGH"   // 高敏感
)

// SensitiveWordAction 处理动作
const (
	SensitiveWordActionReplace = "REPLACE" // 替换为 ***
	SensitiveWordActionReject  = "REJECT"  // 拒绝发送
	SensitiveWordActionWarn    = "WARN"    // 警告但允许发送
)

// CreateSensitiveWordReq 创建敏感词请求
type CreateSensitiveWordReq struct {
	Word     string `json:"word" binding:"required,max=100"`
	Category string `json:"category" binding:"required,oneof=political violence porn ad abuse other"`
	Level    string `json:"level" binding:"required,oneof=LOW MEDIUM HIGH"`
	Action   string `json:"action" binding:"required,oneof=REPLACE REJECT WARN"`
}

// UpdateSensitiveWordReq 更新敏感词请求
type UpdateSensitiveWordReq struct {
	Category  string `json:"category" binding:"omitempty,oneof=political violence porn ad abuse other"`
	Level     string `json:"level" binding:"omitempty,oneof=LOW MEDIUM HIGH"`
	Action    string `json:"action" binding:"omitempty,oneof=REPLACE REJECT WARN"`
	IsEnabled *bool  `json:"isEnabled"`
}

// SensitiveWordListReq 敏感词列表请求
type SensitiveWordListReq struct {
	Category  string `form:"category"`  // 分类筛选
	Level     string `form:"level"`     // 级别筛选
	IsEnabled *bool  `form:"isEnabled"` // 是否启用
	Keyword   string `form:"keyword"`   // 关键词搜索
	Page      int    `form:"page"`
	PageSize  int    `form:"pageSize"`
}

// SensitiveWordListResp 敏感词列表响应
type SensitiveWordListResp struct {
	List     []SensitiveWord `json:"list"`
	Total    int64           `json:"total"`
	Page     int             `json:"page"`
	PageSize int             `json:"pageSize"`
}

// FilterResult 过滤结果
type FilterResult struct {
	Passed         bool     `json:"passed"`         // 是否通过
	FilteredText   string   `json:"filteredText"`   // 过滤后的文本
	HitWords       []string `json:"hitWords"`       // 命中的敏感词
	HighestLevel   string   `json:"highestLevel"`   // 最高敏感级别
	SuggestedAction string  `json:"suggestedAction"` // 建议动作
}

